package cn.itcast.scala.course07

import scala.util.Random

/**
  * 偏函数: 被包在花括号内的没有match的一组case语句
  * create by zhangtian on 2019/1/9
  */
object PartitalFunctionApp extends App {

  val names = Array("AAA", "BBB", "CCC", "DDD", "EEE") ;
  val name = names(Random.nextInt(names.length))

  // 简单的模式匹配
  println("************** 简单的模式匹配 *************")
  name match {
    case "AAA" => print("A老师")
    case "BBB" => print("B老师")
    case "CCC" => print("C老师")
    case "DDD" => print("D老师")
    case "EEE" => print("E老师")
    case _ => print("NO老师")
  }

  // A 输入参数类型 B 输出参数类型
  println()
  def sayChinese: PartialFunction[String, String]= {
    case "AAA" => "A老师"
    case "BBB" => "B老师"
    case "CCC" => "C老师"
    case "DDD" => "D老师"
    case "EEE" => "E老师"
    case _ => "NO老师"
  }

  println(sayChinese("AAA"))
}
